import MatterBody from "./MatterBody";
import MatterManager from "../../managers/MatterManager";

export default class SnowBall1 extends MatterBody {
    /** @prop {name:radius, tips:"半径", type:Int, default:0}*/
    public radius: number = 25;

    /** @prop {name:x, tips:"x坐标", type:Int, default:0}*/
    public x: number;
    /** @prop {name:x, tips:"y坐标", type:Int, default:0}*/
    public y: number;
    /** @prop {name:restitution, tips:"弹力系数", type:Int, default:0}*/
    public restitution: number;
    /** @prop {name:friction, tips:"摩擦力", type:Int, default:0}*/
    public friction: number;
    /** @prop {name:frictionStatic, tips:"静态摩擦力", type:Int, default:0}*/
    public frictionStatic: number;
    /** @prop {name:frictionAir, tips:"空气阻力", type:Int, default:0}*/
    public frictionAir: number;
    /** @prop {name:isStatic, tips:"是否是静止的", type:Bool, default:false}*/
    
    constructor() { super(); }
    
    public snowMan: any;

    public isGrowUp = false;

    public scale = 1;

    onEnable(): void {
        let owner = this.owner as Laya.Sprite;
        this.body = this.matter.Bodies.circle(owner.x, owner.y, this.radius, {
            isStatic: false,
            // isSensor: true,
            // restitution: this.restitution,
            friction: 0,
            frictionStatic: 0,
            frictionAir: 0
        });

        this.addToWorld();

        super.onEnable();

    } 

    onUpdate() {

    }


    public onCollision(event) {
        console.log('ball crash')

        // let other: any;
        // for (const pair of event.pairs) {
        //     if (pair.bodyA === this.body || pair.bodyB === this.body) {
        //         other = pair.bodyA === this.body ? pair.bodyB : pair.bodyA;
        //         break;
        //     }
        // }
        // if (other === this.snowMan) {
        //     return;
        // }

        // let v = this.getVectorByAngle(-this.snowMan.angle, 50);
        // MatterManager.instance.setVelocity(other.parent, v.x, v.y);        

        // let owner = this.owner as Laya.Sprite;
        // owner.removeSelf();
        // MatterManager.instance.removeFromWorld(this.body);
    }


    onDisable(): void {
    }
}